/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;

import controller.SkinBasedController;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Home
 */
public class TouchPad implements Runnable {

    int[] cordinate1, cordinate2;
    int dx, dy, x, y, threshx, threshy, click;
    double[] ratio;

    public TouchPad(int threshx, int threshy) {
        this.threshx = threshx;
        this.threshy = threshy;
        ratio[0]=1;
        ratio[1]=1;
    }



    public void run() {
        try {
            SkinBasedController sc = new SkinBasedController(UserInterface.FinalGUI.left_Camera, UserInterface.FinalGUI.left_Camera);
            sc.run();
            Robot rb = new Robot();
            while (true) {
                cordinate1 = SkinBasedController.ty;
                cordinate2 = SkinBasedController.ty;
                dx = cordinate2[0] - cordinate1[0];
                dy = cordinate2[1] - cordinate1[1];
                dx = (int) (dx * ratio[0]);
                dy = (int) (dy * ratio[1]);
                x = x + dx;
                y = y + dy;
                System.out.println("x="+x+" y="+y);
                rb.mouseMove(x, y);
                if (dx < threshx & dy < threshy) {
                    click = click + 1;
                    if (click == 500) {
                        rb.mousePress(MouseEvent.BUTTON1_MASK);
                        rb.mouseRelease(MouseEvent.BUTTON1_MASK);
                        click = 0;
                    }
                } else {
                    click = 0;
                }
            }

        } catch (AWTException ex) {
            Logger.getLogger(TouchPad.class.getName()).log(Level.SEVERE, null, ex);
        }





    }
}
